
import BaseModel from './BaseModel';
import getLastProto from './utils/getLastProto';

export default (setData, getData) => {

    
    return (models) => {
        let modelInstance = getData('modelInstance');
        
        Object.keys(models).forEach((modelName) => {
            if (!modelInstance[modelName] || !modelInstance[modelName].lock) {
                let baseModel = new BaseModel();
                let Model = models[modelName];
                let lastProto = getLastProto(Model);
    
                Object.setPrototypeOf(lastProto.prototype, baseModel);
                let model = new Model();
    
                modelInstance[modelName] = model;
            }
        });

        setData('modelInstance', modelInstance);
    }
}